class Solution:
	# @param {integer} s
	# @param {integer[]} nums
	# @return {integer}
	def minSubArrayLen(self, s, nums):
		if len(nums) < 1:
			return 0
		i = j = 0
		ans = len(nums)
		temp = nums[0]
		while temp < s and j < len(nums)-1:
			j += 1
			temp += nums[j]
		if temp < s:
			return 0
		ans = j - i + 1
		while temp - nums[i] >= s:
			temp -= nums[i]
			i += 1
			ans -= 1
		while j < len(nums)-1:
			j += 1
			temp += nums[j]
			while temp - nums[i] >= s:
				temp -= nums[i]
				i += 1
				ans = min(ans, j-i+1)
		return ans

if __name__ == '__main__':
	print Solution().minSubArrayLen(15, [5,1,3 ,5,10,7,4,9,2,8])